<?php

/**
 * @author: biggege
 * @since:  2021-09-15 14:15:36
 */

namespace App\Http\Services\Manage;

use Maatwebsite\Excel\Facades\Excel;

class ExportService
{
    public static function download($data, $columns, $filename = '_')
    {
        ini_set('memory_limit', '1280M');
        ini_set("max_execution_time", 6000);
        set_time_limit(0);

        return Excel::download((new ExportDataService($data, $columns)), $filename . '_' . date('YmdHis') . '.xlsx');
    }

    public static function store($data, $columns, $filename = '_')
    {
        ini_set('memory_limit', '1280M');
        ini_set("max_execution_time", 6000);
        set_time_limit(0);

        $filename .= '_' . date('YmdHis') . '.xlsx';

        if (!Excel::store((new ExportDataService($data, $columns)), public_path('excel') . '/' . $filename))
            return false;

        return ['download_url' => "/excel/" . $filename];
    }
}